//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.hs.demo.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;

public class DateUtilMy {
    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
    public static void getDateTime() throws ParseException {
        Calendar now = Calendar.getInstance();
        System.out.println("年: " + now.get(Calendar.YEAR));
        System.out.println("月: " + (now.get(Calendar.MONTH) + 1) + "");
        System.out.println("日: " + now.get(Calendar.DAY_OF_MONTH));
        System.out.println("时: " + now.get(Calendar.HOUR_OF_DAY));
        System.out.println("分: " + now.get(Calendar.MINUTE));
        System.out.println("秒: " + now.get(Calendar.SECOND));
        System.out.println("当前时间毫秒数：" + now.getTimeInMillis());
        System.out.println(now.getTime());

        Date d = new Date();
        System.out.println(d);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateNowStr = sdf.format(d);
        System.out.println("格式化后的日期：" + dateNowStr);

        String str = "2012-1-13 17:26:33";    //要跟上面sdf定义的格式一样
        Date today = sdf.parse(str);
        System.out.println("字符串转成日期：" + today);
        now.set(Calendar.MONTH, 7);
    }
    public DateUtilMy() {
    }

    public static void main(String[] args) {
        Date dayOfCut = getDayOfCut(-1);
        System.out.println(sd.format(dayOfCut));
    }

    public static String getCurrentTime() {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return df.format(new Date());
    }

    public static Calendar getC() {
        Calendar c = Calendar.getInstance();
        return c;
    }

    public static Date getcutMinutes(Date date, Integer min_cut) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(12, min_cut);
        return c.getTime();
    }

    public static Calendar getC(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c;
    }

    public static String getMStr(int month) {
        return month < 10 ? "0" + month : String.valueOf(month);
    }

    public static String getBc() {
        int hour = getC().get(11);
        return hour <= 6 && hour >= 19 ? "夜班" : "白班";
    }

    public static String getBc(Date date) {
        int hour = getC(date).get(11);
        return hour <= 6 && hour >= 19 ? "夜班" : "白班";
    }

    public static Date getDayTimeOfCut(Integer hourPoit, Integer day_cut) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(11, hourPoit);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        calendar.add(6, day_cut);
        Date date = calendar.getTime();
        return date;
    }

    public static String getDayTimeOfCutString(Integer hourPoit, Integer day_cut) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(11, hourPoit);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        calendar.add(6, day_cut);
        Date date = calendar.getTime();
        String dateString = sdf.format(date);
        return dateString;
    }

    public static Date getDayOfCut(Integer day_cut) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(6, day_cut);
        Date date = calendar.getTime();
        return date;
    }

    public static Date getDayOfCut(Date date, Integer day_cut) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(6, day_cut);
        return calendar.getTime();
    }

    public static String getDayTimeOfCutForMat(Integer hourPoit, Integer day_cut) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(getDayTimeOfCut(hourPoit, day_cut));
    }

    public static String getDayTimeOfCutForMatDay(Integer day_cut) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(getDayTimeOfCut(0, day_cut));
    }

    public static String getForMatCutDay(Integer day_cut) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(getDayTimeOfCut(0, day_cut));
    }

    public static Date getDayTimeOfCut(Integer hourPoit, Integer day_cut, Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(11, hourPoit);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        calendar.add(6, day_cut);
        return calendar.getTime();
    }

    public static String getDayTimeOfCutForMatDay(Integer day_cut, Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(getDayTimeOfCut(0, day_cut, date));
    }

    public static Date getCurrentDayTime(Date date, Integer hour) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar c1 = Calendar.getInstance();
        c1.set(1, Integer.valueOf(sdf.format(date).substring(0, 4)));
        c1.set(2, Integer.valueOf(sdf.format(date).substring(5, 7)) - 1);
        c1.set(5, Integer.valueOf(sdf.format(date).substring(8, 10)));
        c1.set(11, hour);
        c1.set(12, 0);
        c1.set(13, 0);
        Date start = c1.getTime();
        return start;
    }

    public static String getCurrentDayTimeFormat(Date date, Integer hour) {
        Calendar c1 = Calendar.getInstance();
        c1.setTime(date);
        c1.set(11, hour);
        c1.set(12, 0);
        c1.set(13, 0);
        Date start = c1.getTime();
        return sdf.format(start);
    }

    public static String getErpDate(String sd) {
        return sd.substring(2).replaceAll("-", ".");
    }

    public static String getErpD(String sd) {
        return sd.substring(2).replaceAll("-", "");
    }

    public static Date getCurrentDayTimeFormatDate(Date date, Integer hour, SimpleDateFormat sdf) {
        if (sdf == null) {
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        }

        Calendar c1 = Calendar.getInstance();
        c1.setTime(date);
        c1.set(11, hour);
        c1.set(12, 0);
        c1.set(13, 0);
        Date start = c1.getTime();
        return start;
    }

    public static String getCurrentDayFormat(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }

    public static String getDayYearMounthDay(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String s = sdf.format(date);
        return s.split("-")[0].substring(2, 4) + "." + s.split("-")[1] + "." + s.split("-")[2];
    }

    public static Date getDayTimeOfCut(Date date, Integer hour, Integer day_cut) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(6, day_cut);
        calendar.set(11, hour);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        Date date1 = calendar.getTime();
        return date1;
    }

    public static Date getDayTimeOfCutForMonth(Date date, Integer hour, Integer month_cut) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(2, month_cut);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        Date date1 = calendar.getTime();
        return date1;
    }

    public static Date getCurrentTimeByCutHour(Integer hour_cut) {
        Calendar calendar0 = Calendar.getInstance();
        calendar0.add(11, hour_cut);
        return calendar0.getTime();
    }

    public static String getCurrentTimeByCutHourFormat(Integer hour_cut) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar0 = Calendar.getInstance();
        calendar0.add(11, hour_cut);
        return sdf.format(calendar0.getTime());
    }

    public static int getCurentHour() {
        Calendar calendar = Calendar.getInstance();
        return calendar.get(11);
    }

    public static String getMonth00(int monthCut) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(2, monthCut);
        int month = calendar.get(2) + 1;
        return month < 10 ? "0" + month : month + "";
    }

    public static int getHour(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(11);
    }

    public static String pickClass(Date date) {
        if (date == null) {
            return "未知";
        } else {
            int hour = getHour(date);
            return hour <= 19 && hour >= 7 ? "白班" : "夜班";
        }
    }

    public static Date getDayByDayCUtAndMonthCut(int dayPoint, int monthCut, Integer poitHour) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(2, monthCut);
        calendar.set(5, dayPoint);
        if (null != poitHour) {
            calendar.set(11, poitHour);
        }

        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar.getTime();
    }

    public static Date getDayByDayCUtAndMonthCutAndYear(int dayPoint, int monthCut, Integer poitHour, int cutYear) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(1, cutYear);
        calendar.add(2, monthCut);
        calendar.set(5, dayPoint);
        if (null != poitHour) {
            calendar.set(11, poitHour);
        }

        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar.getTime();
    }

    public static Date getDayByDayCUtAndMonthCutYearCut(int dayPoint, int monthCut, Integer poitHour, int yearCut) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(2, monthCut);
        calendar.add(1, yearCut);
        calendar.set(5, dayPoint);
        if (null != poitHour) {
            calendar.set(11, poitHour);
        }

        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar.getTime();
    }

    public static Date getCurrentDayLastMonth(Date date, int monthCut, Integer poitHout) {
        Calendar calendar = Calendar.getInstance();
        if (date != null) {
            calendar.setTime(date);
        }

        int year = calendar.get(1);
        int day = calendar.get(5);
        int month = calendar.get(2);
        if (month == 2 && day > 28) {
            if (year % 4 == 0 && day > 29) {
                calendar.set(5, 29);
            } else {
                calendar.set(5, 28);
            }
        }

        Integer[] ini = new Integer[]{4, 6, 11};
        if (day > 30 && Arrays.asList(ini).contains(month) && day == 31) {
            calendar.set(5, 30);
        }

        calendar.set(11, 0);
        if (poitHout != null) {
            calendar.set(11, poitHout);
        }

        calendar.add(2, monthCut);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar.getTime();
    }

    public static Date getCurrentDayLastYear(int year) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(1, calendar.get(1) - 1);
        return calendar.getTime();
    }

    public static Date getDayOfYear(int dayNum, int yearCut, Integer poitHour) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(6, dayNum);
        calendar.add(1, yearCut);
        if (poitHour != null) {
            calendar.set(11, poitHour);
        }

        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar.getTime();
    }

    public static Date getCurrentDayOfYear(int yearCut, Integer poitHour) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(1, calendar.get(1) + yearCut);
        if (poitHour != null) {
            calendar.set(11, poitHour);
        }

        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar.getTime();
    }

    public static Date getCurrentDayOfYear(Date date, int yearCut, Integer poitHour) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        if (poitHour != null) {
            calendar.set(11, poitHour);
        }

        calendar.set(1, calendar.get(1) + yearCut);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar.getTime();
    }
}
